import { _decorator, Component, Node, sys } from 'cc';
import GameEventMgr, { GameEvent } from '../Model/GameEventMgr';
const { ccclass, property } = _decorator;

export enum StorageKey {
    FPTutorialFinish = 'firstPlayerTutorialFinish',
}

@ccclass('LocalStorageCtrl')
export class LocalStorageCtrl {
    static setItem(key: StorageKey | string, value) {
        sys.localStorage.setItem(`${key}`, value);
        console.log(`存储key:${key}`)

        GameEventMgr.Dispatch(GameEvent.UpdateLocalStorageValue, key, value);
    }
    /**
     * 获取number值
     * @param key 
     */
    static getNumberValue(key) {
        let value = this.getItem(key);
        if (value != null && value != undefined) {
            return Number(value);
        } else {
            return 0;
        }
    }
    /**
     * 获取布尔值
     * @param key 
     */
    static getBooleanValue(key) {
        let value = this.getItem(key);
        if (value != null && value != undefined) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 获取字符串
     * @param key 
     */
    static getStringValue(key) {
        let value = this.getItem(key);
        if (value != null && value != undefined) {
            return value + "";
        } else {
            return "";
        }
    }

    static getItem(key) {
        return sys.localStorage.getItem(`${key}`);
    }
}


